package com.sc.controller.vehicle;

import com.sc.domain.VehicleCost;
import com.sc.result.Result;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.result.PageResult;
import com.sc.service.vehicle.IVehicleCostService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/vehicleCost")
@Api(tags = "车辆缴费")
@CrossOrigin
public class VehicleCostController {

    @Autowired
    private IVehicleCostService ivcs;

    /**
     * 添加缴费单
     */
    @PostMapping("/add")
    @ApiOperation("添加缴费单")
    public Result addVehicleCost(@RequestBody VehicleCost vehicleCost){
        Boolean b=ivcs.addVehicleCost(vehicleCost);
        return Result.success();
    }

    /**
     * 查询账单详情
     * @return
     */
    @GetMapping("/selectById")
    @ApiOperation("查询账单详情")
    public Result<VehicleCost> selectById(Integer id){
        VehicleCost pos = ivcs.getById(id);
        return Result.success(pos);
    }
    /**
     * 修改账单情况
     * @return
     */
    @PutMapping("/update")
    @ApiOperation("修改账单情况")
    public Result update(@RequestBody VehicleCost vehicleCost){
        ivcs.updateById(vehicleCost);
        return Result.success();
    }

    /**
     * 根据车位分页查询车位列表
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("分页查询账单列表")
    public PageResult list(String positionName,Integer pageNum, Integer pageSize){
        Page<VehicleCost> page = ivcs.showCosts(positionName,pageNum, pageSize);
        return new PageResult(page.getTotal(),page.getRecords());
    }
    /**
     * 删除账单
     * @return
     */
    @DeleteMapping("/delete")
    @ApiOperation("删除账单")
    public Result delete(Integer id){
        ivcs.removeById(id);
        return Result.success();
    }

    @DeleteMapping("/deleteByIds")
    @ApiOperation("批量删除")
    public Result deleteByIds(@RequestBody List<Integer> ids) {
        ivcs.removeByIds(ids);
        return Result.success();
    }
}
